package com.aoxon.cargo.util;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import com.google.gson.Gson;


/**
 * 数据的转化处理
 * @author ZZJ
 *
 */
public class DataUtil {

	public static Gson gson = new Gson();
	
	/**
	 * 利用序列化深度clone
	 * 
	 * @param oldObj
	 * @return
	 */
	public static Object cloneObj(Object oldObj) {
		Object newObj = null;
		try {
			ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
			ObjectOutputStream out = new ObjectOutputStream(byteOut);
			out.writeObject(oldObj);
			ByteArrayInputStream byteIn = new ByteArrayInputStream(
					byteOut.toByteArray());
			ObjectInputStream in = new ObjectInputStream(byteIn);
			newObj = in.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return newObj;

	}

}
